#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/cred.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>

void *test_get_thread_info_flags_addr(void) {
    return &current->thread_info.flags;
}

unsigned long test_get_seccomp_flag(void) {
    return TIF_SECCOMP;     // TIF_SECCOMP = 0x8
}

MODULE_LICENSE("GPL");

#if 0

/* 
 * objdump -M intel -d current-task.ko 
 */

0000000000000000 <test_get_thread_info_flags_addr>:
   0:   e8 00 00 00 00          call   5 <test_get_thread_info_flags_addr+0x5>
   5:   55                      push   rbp
   6:   65 48 8b 04 25 00 00    mov    rax,QWORD PTR gs:0x0     // 从 gs 段寄存器获取当前任务的 task_struct
   d:   00 00 
   f:   48 89 e5                mov    rbp,rsp
  12:   5d                      pop    rbp
  13:   c3                      ret    
  14:   66 66 2e 0f 1f 84 00    data16 nop WORD PTR cs:[rax+rax*1+0x0]
  1b:   00 00 00 00 
  1f:   90                      nop

0000000000000020 <test_get_seccomp_flag>:
  20:   e8 00 00 00 00          call   25 <test_get_seccomp_flag+0x5>
  25:   55                      push   rbp
  26:   b8 08 00 00 00          mov    eax,0x8          // TIF_SECCOMP
  2b:   48 89 e5                mov    rbp,rsp
  2e:   5d                      pop    rbp
  2f:   c3                      ret    


/* 
 * objdump -d current-task.ko 
 */

0000000000000000 <test_get_thread_info_flags_addr>:
   0:   e8 00 00 00 00          callq  5 <test_get_thread_info_flags_addr+0x5>
   5:   55                      push   %rbp
   6:   65 48 8b 04 25 00 00    mov    %gs:0x0,%rax     // 从 gs 段寄存器获取当前任务的 task_struct
   d:   00 00 
   f:   48 89 e5                mov    %rsp,%rbp
  12:   5d                      pop    %rbp
  13:   c3                      retq   
  14:   66 66 2e 0f 1f 84 00    data16 nopw %cs:0x0(%rax,%rax,1)
  1b:   00 00 00 00 
  1f:   90                      nop

0000000000000020 <test_get_seccomp_flag>:
  20:   e8 00 00 00 00          callq  25 <test_get_seccomp_flag+0x5>
  25:   55                      push   %rbp
  26:   b8 08 00 00 00          mov    $0x8,%eax        // TIF_SECCOMP
  2b:   48 89 e5                mov    %rsp,%rbp
  2e:   5d                      pop    %rbp
  2f:   c3                      retq   


不需要阅读内核源代码，直接用编译器就能帮我们找出来需要用到的指令。

获取当前任务的 task_struct 的指令：

    mov rax, qword ptr gs:[0x0]     ; 从 gs 段寄存器获取当前任务的 task_struct

#endif